package com.autcar.training.controller;

import com.autcar.training.entity.FeedBack;
import com.autcar.training.service.FeedBackService;
import com.autcar.training.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.controller
 * @ClassName: FeedBackController
 * @Author: YHHHH
 * @Description:
 * @Date: 2020/8/31 9:00
 * @Version: 1.0
 */
@RestController
public class FeedBackController {
    @Resource
    private FeedBackService feedBackService;

    @Resource
    private OrderService orderService;


    /*
    返回所有反馈
     */
    @GetMapping("/feedBackList")
    public List<FeedBack> feedBackList(){
        List<FeedBack> allFeedBack = feedBackService.findAllFeedBack();
        return allFeedBack;
    }
    /*
    删除一条反馈
     */
    @GetMapping("/deleteFeedBack/{id}/{oid}")
    public String deleteFeedBack(@PathVariable("id") Integer id,@PathVariable("oid") Integer oid){
        int i = feedBackService.deleteFeedBackById(id);
        orderService.updateStatusFalse(oid);
        return null;
    }

    /*
    增加一条反馈
     */
    @PostMapping("/addFeedBack")
    public String addFeedBack(@RequestBody FeedBack feedBack){
        feedBackService.addFeedBack(feedBack);
        orderService.updateStatusTrue(feedBack.getOid());
        return null;
    }

}